Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests: Fix One Definition Rule violation caused by overlinking #1997

Conversation

jrohel
Copy link
Contributor

@jrohel jrohel commented Jan 9, 2025

Closes: #1893

The libdnf5 library unit tests use the private methods of the tested libdnf5 library. The BaseTestCase class used as a parent of many test scenarios, not only libdnf5 but also libdnf5-cli and other unit tests, provides the add_system_pkg method, which also uses private methods of the libdnf5 library. Because the private methods have hidden symbols, they are not exported by the libdnf5 shared library. To access the symbols of the private methods, unit tests link libdnf5 statically instead of using the libdnf5 shared library. This is fine for unit tests of the libdnf5 library. The problem is with unit tests of other components (e.g. libdnf-cli) that link the shared libdnf5 library. Due to this, in these tests the libdnf5 library was linked statically because of used class BaseTestCase and at the same time the shared libdnf5 library was linked.

The problem was solved by moving the add_system_pkg method from the BaseTestCase class to the newly created inherited LibdnfPrivateTestCase class, which is only used in the libdnf5 library unit tests. Thus, only in these tests must libdnf5 be linked statically. The tests of the other components still use the BaseTestClass class, which now uses only public (API) functions from the libdnf5 library. These tests now only link the shared version of the libdnf5 library.

The libdnf5 library unit tests use the private methods of the tested
libdnf5 library. The `BaseTestCase` class used as a parent of many test
scenarios, not only libdnf5 but also libdnf5-cli and other unit tests,
provides the `add_system_pkg` method, which also uses private methods
of the libdnf5 library. Because the private methods have hidden symbols,
they are not exported by the libdnf5 shared library. To access
the symbols of the private methods, unit tests link libdnf5 statically
instead of using the libdnf5 shared library. This is fine for unit tests
of the libdnf5 library. The problem is with unit tests of other
components (e.g. libdnf-cli) that link the shared libdnf5 library.
Due to this, in these tests the libdnf5 library was linked statically
because of used class `BaseTestCase` and at the same time the shared
libdnf5 library was linked.

The problem was solved by moving the `add_system_pkg` method from
the `BaseTestCase` class to the newly created inherited
`LibdnfPrivateTestCase` class, which is only used in the libdnf5 library
unit tests. Thus, only in these tests must libdnf5 be linked statically.
The tests of the other components still use the `BaseTestClass` class,
which now uses only public (API) functions from the libdnf5 library.
These tests now only link the shared version of the libdnf5 library.
@jan-kolarik jan-kolarik self-assigned this Jan 10, 2025
Copy link
Member

@jan-kolarik jan-kolarik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I can confirm this fixes locally running the CLI tests without emitting the "double free or corruption" error. This will hopefully unblock the OpenSUSE builds.

@jan-kolarik jan-kolarik added this pull request to the merge queue Jan 10, 2025
Merged via the queue into rpm-software-management:main with commit e8e40a6 Jan 10, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

libdnf5::rpm::VersionlockCondition::VALID_COMPARATORS overlinkinkg in libdnf5-cli test violates ODR
2 participants